package ca.uwo.android.alumni;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.AdapterView.OnItemClickListener;
import ca.uwo.android.HomeScreenActivity;
import ca.uwo.android.R;
import ca.uwo.android.giveback.GiveBack;
import ca.uwo.android.rss.events.RssDatesFeed;

public class AlumniMain extends HomeScreenActivity {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		GridView gridView = (GridView) findViewById(getGridViewId());
		gridView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View v,
					int position, long id) {
				if (position == 0)
					startActivityFromChild(AlumniMain.this, new Intent(
							AlumniMain.this, AlumniHomecoming.class), -1);
				else if (position == 1)
					startNewsActivity(
							getString(R.string.alumni_gazette_feed),
							getString(R.string.alumni_gazette_title));
				else if (position == 2)
					startEventCalendarActivity(
							getString(R.string.alumni_events_feed),
							getString(R.string.alumni_events_title),
							RssDatesFeed.ALUMNIEVENTS);
				else if (position == 3)
					startActivityFromChild(AlumniMain.this, new Intent(
							AlumniMain.this, AlumniBranches.class), -1);
				else if (position == 4)
					startNotableAlumniActivity(
							getString(R.string.alumni_notable_feed),
							getString(R.string.alumni_notable_title));

				else if (position == 5)
					startActivityFromChild(AlumniMain.this, new Intent(
							AlumniMain.this, GiveBack.class), -1);

				else
					alert("Not yet implemented.", false);

			}

		});

	}
	
	/**
	 * Start a notable alumni activity
	 * 
	 * @param url
	 *            the url of the feed
	 * @param header
	 *            the name that should be put in the screen header
	 */
	protected void startNotableAlumniActivity(String url, String header) {
		Intent intent = new Intent(this, ca.uwo.android.alumni.AlumniNotable.class);
		intent.putExtra("URL", url);
		intent.putExtra("HEADER", header);
		startActivity(intent);
	}


	@Override
	protected Integer[] getModuleIcons() {
		Integer[] icons = { R.drawable.alumni_homecoming,
				R.drawable.alumni_gazette, R.drawable.alumni_events,
				R.drawable.alumni_branch, R.drawable.alumni_notable,
				R.drawable.give_back

		};
		return icons;
	}

	@Override
	protected int getContentViewId() {
		return R.layout.alumni_main;
	}

	@Override
	protected int getGridViewId() {
		return R.id.alumniGridView;
	}

	@Override
	protected int getModuleNames() {
		return R.array.alumni_module_name_array;
	}

}
